<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>

<button id="btn" onclick="randomImage()" style="width: 250px;height: 50px">随机图片</button>
<div>
  <img id="pic" src="">
</div>
<script>
  /*假定images文件夹下有7张图片bg-1.png~ bg-7.png
  请用js实现: 每次随机抽取一张,显示在页面的div标签内。*/
  function randomImage() {
    var index = Math.floor(Math.random() * 2) + 1;
    var path = `images/bg-${index}.jpg`;
    const randomImageElement = document.getElementById('pic');
    randomImageElement.src = path;
  }
</script>
</body>
</html>